package com.bbx.wcdemo;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class WCReduce   extends Reducer<Text, IntWritable,Text, IntWritable> {
    IntWritable intWritable =new IntWritable();
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int sum = 0;
        //按照字典顺序key分组，加载每一组key，key组内的value值求和
        for(IntWritable value:values){
            sum += value.get();
        }
        intWritable.set(sum);
        context.write(key,intWritable);
    }
}
